import { Button, Card, Input, Select, Space, DatePicker } from "antd";
import { useState } from "react";
import dayjs from "dayjs";
import './index.scss'
const { Option } = Select
const { RangePicker } = DatePicker
export default function Search(props) {
    const [val, setVal] = useState('')
    const [year, setYear] = useState(null);
    const [fxlx, setFxlx] = useState('');    

    const handleSearch = () => {
    const base = {
        keyword: val
    };
    
    // 如果启用风险搜索，则添加 year 和 fxlx
    if (props.isFengxian) {
        base.year = year ? year.format('YYYY') : '';
        base.fxlx = fxlx;
    }

    props.onSearch && props.onSearch(base);
    };

    const handlereset = () => {
    const base = {
        keyword: ''
    };

    setVal('');
    setYear(null);
    setFxlx('');

    if (props.isFengxian) {
        base.year = '';
        base.fxlx = '';
    }

    props.onSearch && props.onSearch(base);
    };
    // const handleSearch = () => {
    //     props.onSearch && props.onSearch(val)
    // }
    // const handlereset = () => {
    //     setVal('')
    //     props.onSearch && props.onSearch('')
    // }
    return (
        <Card className="search">
            <Space direction="horizontal">
                {props.isFengxian && (
                // <><DatePicker style={{ width: '160px' }} picker='year' defaultValue={dayjs(new Date())} placeholder={'年度'} />
                //     <Select style={{ width: '160px' }} placeholder={'请选择风险类型'}>                
                    <>
                    <DatePicker
                    style={{ width: '160px' }}
                    picker="year"
                    value={year}
                    onChange={(date) => setYear(date)}
                    placeholder="年度"
                    />
                    <Select
                    style={{ width: '160px' }}
                    value={fxlx}
                    onChange={(value) => setFxlx(value)}
                    placeholder="请选择风险类型"
                    allowClear
                    >
                        <Option value=""></Option>
                        <Option value="与小微企业交易">与小微企业交易</Option>
                        <Option value="与新成立公司交易">与新成立公司交易</Option>
                        <Option value="与贸易公司交易">与贸易公司交易</Option>
                        <Option value="高频风险">高频风险</Option>
                        <Option value="大额风险">大额风险</Option>
                        <Option value="异常用途">异常用途</Option>
                        <Option value="提现异常">提现异常</Option>
                        <Option value="与偿债能力不足公司交易">与偿债能力不足公司交易</Option>
                        <Option value="违反八项规定">违反八项规定</Option>
                        <Option value="交易对手存在司法风险">交易对手存在司法风险</Option>
                        <Option value="提现风险">提现风险</Option>
                        <Option value="交易对手存在经营风险">交易对手存在经营风险</Option>
                        <Option value="命中司库黑名单">命中司库黑名单</Option>
                        <Option value="循环贸易">循环贸易</Option>
                        <Option value="上下游相同实际控制人">上下游相同实际控制人</Option>
                        <Option value="融资性贸易">融资性贸易</Option>
                        <Option value="体外循环">体外循环</Option>
                        <Option value="同名称交易">同名称交易</Option>
                        <Option value="上下游相同董监高">上下游相同董监高</Option>
                        <Option value="空转走单">空转走单</Option>
                        <Option value="两头在外">两头在外</Option>
                        <Option value="上下游相同地址或电话">上下游相同地址或电话</Option>
                        <Option value="发票不必要">发票不必要</Option>                        
                    </Select></>)}
                {props.isShequ && <><Select style={{ width: '160px' }} placeholder={'请选择风险类型'}>
                    <Option value="0">空转走单</Option>
                    <Option value="1">xxxxx</Option>
                </Select><RangePicker ></RangePicker></>}
                <Input placeholder="请输入查询内容" value={val} onChange={(e) => setVal(e.target.value)} allowClear />
                <Button type="primary" htmlType="submit" onClick={handleSearch}>查询</Button>
                <Button htmlType="reset" onClick={handlereset}>重置</Button>
            </Space>
        </Card>
    )
}